package com.yhx.controller;

import com.yhx.iservice.ISetmealService;
import com.yhx.pojo.Setmeal;
import com.yhx.utils.MessageConstant;
import com.yhx.utils.Result;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/setmeal")
public class SetmealController {
    @Reference
    private ISetmealService setmealService;

    @GetMapping
    public Result list(){
        try {
            List<Setmeal> list = setmealService.lits();
            return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS,list);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_SETMEAL_FAIL);
        }
    }
    /**
     * 前段需要以后整个setmeal,包括了这一些检查组，
     * 还有这些检查组所包含的那些检查项
     *
     */
    @GetMapping("/{id}")
    public Result getById(@PathVariable int id){
        try {
            return setmealService.getSetmeal(id);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,MessageConstant.QUERY_SETMEAL_FAIL);
        }
    }
    @GetMapping("/getBaseInfo/{id}")
    public Result getBaseInfo(@PathVariable int id){
        try {
            Setmeal byid = setmealService.getByid(id);
            return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS,byid);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,MessageConstant.QUERY_SETMEAL_FAIL);
        }
    }

}
